package com.example.minefieldkeepercloud.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.minefieldkeepercloud.R;
import com.example.minefieldkeepercloud.view.lazyviewpager.LazyFragmentPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class HomeFragment extends Fragment implements LazyFragmentPagerAdapter.Laziable {
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    @BindView(R.id.tablayout)
    TabLayout tablayout;
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fg_homepage, container, false);
        ButterKnife.bind(this, view);
        init();
        return view;
    }


    private void init()
    {
        List<Fragment> list=new ArrayList<>();
        list.add(new MineManagerFragment());
        list.add(new StaffManagerFragment());
        list.add(new MineMonitorFragment());
        list.add(new ServiceEndpointFragment());
        List<String> listt=new ArrayList<>();
        listt.add("矿场管理");
        listt.add("员工管理");
        listt.add("矿机监控");
        listt.add("服务端点");
        tablayout.setupWithViewPager(viewpager);
        viewpager.setAdapter(new MyAdapter(getChildFragmentManager(), list,listt));

    }


    public  static class MyAdapter extends FragmentPagerAdapter {
        List<Fragment> fragments;
        List<String> list;
        public MyAdapter(FragmentManager fm, List<Fragment> fragments, List<String> list) {
            super(fm);
            this.fragments=fragments;
            this.list=list;
        }


        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }


        @Override
        public int getCount() {
            return fragments.size();
        }


        @Override
        public CharSequence getPageTitle(int position) {
            return list.get(position);
        }
    }

}
